package com.liwy3;

import cn.hutool.core.util.RandomUtil;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;

import java.util.Timer;
import java.util.TimerTask;

/**
 * @Author: Crazy4J
 * @Date: 2023年12月20日
 */
public class TP {

    static String cookie = "uid=_NoUse_U6153786a354897f242f772; dadui2_session=eyJpdiI6IjRSWndmbHdLaGZsOHBTVzR5c2FQWGc9PSIsInZhbHVlIjoiNHNYckJRVkNWeitWb25cLzYxMlhoNm9yN1UzOW9rNlBibnRUNnpBMitGOGVpTlN5QytqcnRtc3MrbHpLajU0alwvWGFCbVwvWGdCZDE2c3lodDYzTHB3eU44RlwvXC8wVWdOa0RJckF5UzdvWk9QVGFzaStCRkdMQkhzVmxHVlpEOXkyUSIsIm1hYyI6ImE0NGQyNTA0MzA4MDZmOTg0NGY5MThmM2UyMzc0YjZiMjQ0MDU5MDY5N2Y4ODZiZTViZWFkMGQ2YzM0OTVjOGUifQ%3D%3D; X-Trace-ID=c3b2ff5d-664b-4e14-af94-18fabdf9a823; dadui2_session=eyJpdiI6IjBtVFwvTG4rUFUySW5cL0NwdXlSZlRNQT09IiwidmFsdWUiOiI1dnVBV0N0elFubG4wM05cLyttM0xFckZkYjZLNG1vTUlKSmR6c0I2cGwxb3QySG1JUmppWGdIcE1jelR0cURtRGVlaWJ2RUFNclY5SUlSRVNFS3JjSFNOQVFHc01rRDZxMHpGbkh3TjR0eStGMTBtMTRTUHlxdHE1S3lodDNGZjAiLCJtYWMiOiI4ODBiZmEyZGVmM2I4NWQ0NjljMjU1NWY0YjhkZjc2MzZlZTI3YzdmODg0NTYwNzcxZTU0NGQ4NTJmNGYxYWEwIn0%3D";
    static YQHttp.Request request = YQHttp.newRequest();

    static String domain = "https://i.mydadui.com/sec/action";

    static {
        request = addHeader(request);
    }

    public static YQHttp.Request addHeader(YQHttp.Request request) {
        request.addHeader("Content-Type", "application/json;charset=UTF-8")
                .addHeader("Sec-Fetch-Mode", "cors")
                .addHeader("Host", "i.mydadui.com")
                .addHeader("Accept-Encoding", "gzip, deflate, br")
                .addHeader("Sec-Fetch-Site", "same-origin")
                .addHeader("Accept-Language", " zh-CN,zh-Hans;q=0.9")
                .addHeader("Origin", "https://i.mydadui.com")
                .addHeader("Referer", "https://i.mydadui.com/kayu53?rkid=Vqku7950")
                .addHeader("User-Agent", "Mozilla/5.0 (iPhone; CPU iPhone OS 17_1_2 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148 MicroMessenger/8.0.30(0x18001e32) NetType/4G Language/zh_CN")
                .addHeader("Sec-Fetch-Dest", "empty")
                .addHeader("Cookie", cookie);
        return request;
    }

    public static void submit() {

        delResponse(request.setUrl(domain).setPostBody(Data.HEAD_1()).json().getContent());
        delResponse(request.setUrl(domain).setPostBody(Data.HEAD_2()).json().getContent());
        delResponse(request.setUrl(domain).setPostBody(Data.HEAD_3()).json().getContent());

        delResponse(request.setUrl(domain).setPostBody(Data.Data_1()).json().getContent());
        delResponse(request.setUrl(domain).setPostBody(Data.Data_2()).json().getContent());
        delResponse(request.setUrl(domain).setPostBody(Data.Data_3()).json().getContent());
        delResponse(request.setUrl(domain).setPostBody(Data.Data_4()).json().getContent());
        delResponse(request.setUrl(domain).setPostBody(Data.Data_5()).json().getContent());
        delResponse(request.setUrl(domain).setPostBody(Data.Data_6()).json().getContent());
        delResponse(request.setUrl(domain).setPostBody(Data.Data_7()).json().getContent());
        delResponse(request.setUrl(domain).setPostBody(Data.Data_8()).json().getContent());
        delResponse(request.setUrl(domain).setPostBody(Data.Data_9()).json().getContent());
        delResponse(request.setUrl(domain).setPostBody(Data.Data_10()).json().getContent());
        delResponse(request.setUrl(domain).setPostBody(Data.Data_11()).json().getContent());
        delResponse(request.setUrl(domain).setPostBody(Data.Data_12()).json().getContent());


    }

    private static void delResponse(String content) {
        JSONObject jsonObject = JSONUtil.parseObj(content);
        Object code = jsonObject.get("code");
        if (!"200".equals(String.valueOf(code))) {
            System.out.println("接口报错:" + content);
        }
        System.out.println(content);
        try {
            Thread.sleep(Long.parseLong(RandomUtil.randomNumbers(2)));
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
    }

    public static void main(String[] args) {
        System.out.println("开始投票");
        new Timer().schedule(new TimerTask() {
            @Override
            public void run() {
                for (int i = 0; i < 10; i++) {
                    submit();
                }
            }
        }, 6000, 1000);
    }

}
